package com.IMI.DatabaseActivity;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class DataViewAdapter extends BaseAdapter {

	private Context context;
	private List<Data> DataList;
	private int selectedPosition;

	public DataViewAdapter(Context context, ArrayList<Data> datalist) {
		// TODO Auto-generated constructor stub
		this.DataList = datalist;
		this.context = context;
		this.selectedPosition = Adapter.NO_SELECTION;
	}

		
	public int getSelectedPosition() {
		return selectedPosition;
	}

	
	public int getCount() {
		return DataList.size();
	}

	
	public Data getItem(int position) {
		return DataList.get(position);
	}

	
	public long getItemId(int position) {
		return position;
	}
	

	
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null){
			//Log.d("test","here1");
			DataView temp = new DataView(context,DataList.get(position).getField1(),DataList.get(position).getField2(),DataList.get(position).getField3());
			return temp;
		}
		
		else{
			//Log.d("test","here2");
			((DataView) convertView).setField1(DataList.get(position).getField1());
			((DataView) convertView).setField2(DataList.get(position).getField2());
			((DataView) convertView).setField3(DataList.get(position).getField3());
			return convertView;
		}
	}
}